'use strict';

/* Controllers */

angular.module('myApp.controllersMain', [])
        .controller('MainCtrl', ['$scope', '$location',
            function($scope, $location) {

                $scope.href = function(url) {
                    $location.path(url);
                };
            }
        ])
        .controller('MainAboutCtrl', ['$scope', '$location',
            function($scope, $location) {
                
                $('#popupQuitGameId').off('click');
                $('#popupQuitGameId').on('click', function() {
                    $location.path('/game/quit');
                    $scope.$apply();
                    $('#popupQuitGame').modal('hide');
                });
                $('#popupQuitGame').modal('show');
                
            }
        ])
        .controller('MainStatsCtrl', ['$scope', '$location', 'serviceStats',
            function($scope, $location, serviceStats) {
                $scope.stats = serviceStats.getAll();
                $scope.confirm = function() {
                    $('#popupResetStatConfirmId').off('click');
                    $('#popupResetStatConfirmId').on('click', function() {
                        serviceStats.reset();
                        $location.path('/');
                        $scope.$apply();               
                        $('#popupResetStatConfirm').modal('hide');
                    });
                    $('#popupResetStatConfirm').modal('show');
                }
            }
        ])
        .controller('MainSettingCtrl', ['$scope', 'serviceStorage', '$location',
            function($scope, serviceStorage, $location) {

                console.log(serviceStorage);

                $scope.setting = {
                    'size' : serviceStorage.getItem('size'),
                    'one' : serviceStorage.getItem('one'),
                    'scroll' : (serviceStorage.getItem('scroll') == 'true'),
                    'adjust' : (serviceStorage.getItem('adjust') == 'true')
                };

                $scope.submit = function() {
                    console.log($scope.setting);
                    serviceStorage.setItem('size', $scope.setting.size);
                    serviceStorage.setItem('one', $scope.setting.one);
                    serviceStorage.setItem('scroll', $scope.setting.scroll);
                    serviceStorage.setItem('adjust', $scope.setting.adjust);
                    console.log(serviceStorage);
                    
                    $location.path('/main');
                };
            }
        ]);
        